<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="./js/vue.js"></script>
    <title>Document</title>
</head>

<body>
    <div id="app">
        <h2>{{numer}}</h2>
        <p>{{text}}</p>
        <div v-for="(item,index) in list" :key="index">{{index}}.{{item.text}}
            <p><button v-on:click="list.splice(index,1)">删除</button>
                <button v-on:click="updateItem(item,index)">修改</button>
            </p>
        </div>
        <hr>
        <div>
            <input type="text" v-model="newtext" placeholder="请输入!">
            <button v-on:click="addlist">提交留言</button>
        </div>
        <!-- <div v-for="(item,index) in list" :key="index">
            {{index}}. {{item.title}}
            <p><button v-on:click="list.splice(index,1)">删除</button> <button
                    v-on:click="updateItem(item,index)">修改</button></p>
        </div> -->
    </div>
</body>
<script>
    const vm = new Vue({
        el: "#app",
        data: {
            numer: 2116,
            text: "学好/vue",
            message: `页面加载于` + new Date().toLocaleString(),
            seen: true,
            newtext: "",
            list: [
                { text: '好好学习' },
                { text: '好好工作!' },
                { text: '好好学Vue!' }

            ]
        },
        methods: {
            addlist() {
                this.newtext && this.list.push({
                    text: this.newtext
                })
            },
            updateItem(item, index) {
                var text = window.prompt(index, item.text)
                if (text && item.text != text) {
                    this.list.splice(index, 1, { text })
                    console.log("??")
                }
            }
        }
    })
</script>

</html>